package pers.mingshan.thread.thread;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * 实现  定时器  
 *   2秒炸一次，然后4秒再炸一次   ，循环执行
 * @author mingshan
 *
 */
public class TimerDemo2 {
    private static int count=0;

    public static void main(String[] args) {
        class myTimerTask extends TimerTask {
            @Override
            public void run() {
                System.out.println("booming-----");
                count = (count + 1) % 2;
                new Timer().schedule( new myTimerTask(), 2000 + 2000 * count);
            }
        }

        new Timer().schedule(new myTimerTask(), 2000);
        while (true) {
            System.out.println(new Date().getSeconds());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
